package com.css.bjdt_core.reportExamine.service;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Chain;
import org.nutz.dao.Condition;
import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_core.reportExamine.entity.RptUnitSubmitInfo;
import com.css.bjdt_core.reportExamine.entity.ViewUnitSubmitInfo;
import com.css.bjdt_core.util.CommonUtil;
import com.css.bjdt_core.util.PageQuerys;

@Service
public class RptUnitSubmitInfoService {

	@Autowired
	private Dao dao;

	/**
	 * 新增单位上报信息
	 * @param rusi
	 * @return
	 */
	public RptUnitSubmitInfo insert(RptUnitSubmitInfo rusi) {
		if (StringUtils.isEmpty(rusi.getId())) {
			rusi.setId(CommonUtil.getUUID());
		}
		return dao.insert(rusi);
	}

	/**
	 * 更新单位上报信息
	 * @param rusi
	 * @return
	 */
	public int update(RptUnitSubmitInfo rusi) {
		return dao.updateIgnoreNull(rusi);
	}

	/**
	 * 上报报表，将报表审核状态置为2
	 * @param cdn
	 * @return
	 */
	public int submitReportsByIds(Condition cdn) {
		return dao.update(RptUnitSubmitInfo.class, Chain.make("STATE", 2), cdn);
	}

	/**
	 * 按照单位ID查询相应的单位上报信息的分页数据
	 * @param cnd
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public Map queryByUnitIdInPage(Condition cnd, int pageNum, int pageSize) {

		return PageQuerys.ligerGridQuery(dao, RptUnitSubmitInfo.class, cnd, pageNum, pageSize);
	}

	public Map queryViewInfoByUnitIdInPage(Condition cnd, int pageNum, int pageSize) {
		return PageQuerys.ligerGridQuery(dao, ViewUnitSubmitInfo.class, cnd, pageNum, pageSize);
	}

	/**
	 * 取消上报报表，将报表审核状态置为1
	 * @param cdn
	 * @return
	 */
	public int cancelSubmitRptsByIds(Condition cdn) {
		// TODO Auto-generated method stub
		return dao.update(RptUnitSubmitInfo.class, Chain.make("STATE", 1), cdn);
	}
}
